----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 22401 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 1024
SPELL.m_sName = "Disappearing Strike"
SPELL.m_sToolTip =	"Appear behind the target, stunning them for 2 seconds and dealing 100% weapon damage."
SPELL.m_sIcon = "devin/blackbetty/spells/rogue/disappearingstrike.png"
SPELL.m_iCoolDown = 12
SPELL.m_iManaCost = 0
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_MAA
SPELL.m_bRecastWhileCasting = false

---------------------------------------------------------------------------------------

local range = 100

function SPELL:Cast( pl, target )
	
	print(self.m_sName)
	if(target && target:IsValid() && target != pl ) then
		pl.InSpellAnimation = true
		if(pl:IsPlayer())then
			pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_KNIFE)
		elseif(pl.Bear != nil)then
			pl.Bear.Attacking = true
			pl.Bear.CurSequence = "attack"..math.random(1,2)..""
		else
			pl:RestartGesture(ACT_HL2MP_GESTURE_RANGE_ATTACK_KNIFE)
		end
		pl:EmitSound("devin/blackbetty/weapons/swing/1h_"..math.random(1,3)..".wav", 100, 100+math.random(-10,10))
		--ParticleEffectAttach( "strike", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
			timer.Simple(0.2, function()
				if(target and pl:GetPos():Distance(target:GetPos()) < self.m_iRange)then
					pl:EmitSound("devin/blackbetty/weapons/rogue/shadowstep.wav", 100, 100)
					if(target:IsPlayer())then
						--local b = AddEffect(target, 3, 2)
					end
					pl:SetPos(target:GetPos())
					pl:SetAngles(target:GetAngles())
					ParticleEffect( "shadowstep", pl:GetPos(), Angle(0,0,0), pl )
					ParticleEffect( "shadowstep", target:GetPos(), Angle(0,0,0), target )
					UpdatePlayerResource(pl, 30, true)
					self:Effect(pl, target)
					--self:ApplySpellMods(self, pl, target)
				end
			end)
	end
end

function SPELL:Effect(pl, target)

	local weapon = nil
	if(pl:IsPlayer())then
		weapon = pl:GetWeapon("weapon_all")
	else
		target = pl.Target
	end
	pl:EmitSound("devin/blackbetty/weapons/RendTarget.wav", 100, 80+math.random(-10,10))
	ParticleEffect( "pummel_hit", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), pl )
	ParticleEffect( "player_blood", target:GetPos() + Vector(0, 0, 46) + (target:GetAngles():Forward()*6), Angle(0,0,0), pl )
	if(SERVER)then
		if(weapon)then
			self:DealDamage(weapon.MinWeaponDamage*1, weapon.MaxWeaponDamage*1, pl, target, DMG_GENERIC)
		else
			self:DealDamage(pl.MinDamage*1, pl.MaxDamage*1, pl, target, DMG_GENERIC)
		end
	end
end




